﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Objects;
using System.Linq;
using System.Web;

namespace DuelQuizzServer
{

    public partial class Category
    {
        private static Entities context;
        private static DbSet<Category> entities{        
            get{
                if( Category.context == null){
                    Category.context = new Entities();
                    Category.context.Configuration.ProxyCreationEnabled = false;
                }
                return context.Category;
            }
        }


        internal static List<Category> getCategories(int limit)
        {
            List<Category> list;
            var r = new Random();

            list = Category.entities.ToList();
            if (limit > 0) {
                list = Utils.shuffle(list).Take(limit).ToList();
            }

            return list;
        }

        internal static void add(Category c)
        {
            Category.entities.Add(c);
            Category.context.SaveChanges();
        }

        internal static Category find(int index)
        {
            Category category = Category.entities.Find(index);
            if (category == null)
                return null;
            else{
                return category;              
            }
        }

    }
}